package com.ps.utils;


import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class DBRealm extends AuthorizingRealm {
//    @Resource
//    private UserService userService;
//    @Resource
//    private PermissionService permissionService;
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
//        User user= (User) principalCollection.getPrimaryPrincipal();
//        SimpleAuthorizationInfo info=new SimpleAuthorizationInfo();
//        List<String> list = permissionService.getPermCodeList(user.getUserRole());
//        info.addStringPermissions(list);
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
//        String userCode= (String) token.getPrincipal();
//        User user = userService.findUser(userCode);
//        if (user==null){
//            return null;
//        }
//        SimpleAuthenticationInfo info=new SimpleAuthenticationInfo(user,user.getPassword(), ByteSource.Util.bytes(user.getSalt()),super.getName());
        return null;
    }
}
